package com.zhiyiang.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zhiyiang.Vo.OrderDataVO;
import com.zhiyiang.Vo.OrderVO;
import com.zhiyiang.Vo.PageResult;
import com.zhiyiang.mapper.RoomMapper;
import com.zhiyiang.pojo.Orders;
import com.zhiyiang.pojo.Room;
import com.zhiyiang.service.order.OrderService;
import com.zhiyiang.service.room.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    //查询当前登录用户的所有订单
    @GetMapping("/getLoginOrder/{usercode}/{current}/{size}")
    public Page<OrderVO> getLoginOrder(@PathVariable("usercode") String usercode,
                                       @PathVariable("current") Integer current,
                                       @PathVariable("size") Integer size){
        System.out.println(usercode);
        return orderService.getLoginOrder(usercode,current,size);
    }
    //查看未审核的订单
    @GetMapping("/examOrder/{usercode}/{current}/{size}")
    public Page<OrderVO> examOrder(@PathVariable("usercode") String usercode,
                                       @PathVariable("current") Integer current,
                                       @PathVariable("size") Integer size){
        System.out.println(usercode);
        return orderService.examOrder(usercode,current,size);
    }
    @GetMapping(value = "/findAll/{current}/{size}")
    public Page<OrderVO> doOrder(@PathVariable("current") Integer current, @PathVariable("size") Integer size){
        Page<OrderVO> allOrders = orderService.getAllOrders(current, size);
        return allOrders;
    }

    @GetMapping("/list/{usercode}/{query}/{pagenum}/{pagesize}")
    public Page<OrderVO> findUserByPage(@PathVariable("usercode") String usercode,
                                        @PathVariable("query") String query,
                                        @PathVariable("pagenum") Integer pagenum,
                                        @PathVariable("pagesize") Integer pagesize){
        Page<OrderVO> allOrders = orderService.findUserByPage(usercode,query,pagenum,pagesize);
        return allOrders;
    }
    //根据用户名查询订单
    @GetMapping (value = "/findOrder/{query}/{current}/{size}")
    public Page<Orders> doOrder(@PathVariable("query") String query,@PathVariable("current") Integer current,@PathVariable("size") Integer size){
        Page<Orders> allorders = orderService.getOrders(query,current,size);
        return allorders;
    }
    //根据酒店名查询订单
    @GetMapping("hotelList/{query}/{current}/{size}")
    public Page<OrderVO> getHotelOrder(@PathVariable("query") String query,
                                      @PathVariable("current") Integer current,
                                      @PathVariable("size") Integer size){
        return orderService.getHotelOrder(query,current,size);
    }

    //获取当前行订单
    @GetMapping(value = "/getOrder/{id}")
    public Orders getOrders(@PathVariable("id") Integer id){
        Orders orders = orderService.getOrders(id);
        return orders;
    }
    //添加订单
    @PostMapping(value = "/addOrder")
    public Boolean doOrder(@RequestBody OrderVO orders){
        System.out.println(orders.toString());
        Boolean flag = orderService.addOrders(orders);
        System.out.println(flag);
        return flag;
    }
    //更新房间
    @PutMapping(value = "updateOrder/{id}")
    public Boolean updateOrder(@PathVariable("id") String id,
                               @RequestBody Orders orders){
        Boolean flag = orderService.updateOrders(id, orders);
        return flag;
    }

    //删除当前行酒店
    @GetMapping(value = "/deleteOrder/{id}")
    public Boolean deleteOrder(@PathVariable("id") String id){
        Boolean flag = orderService.deleteOrder(id);
        return flag;
    }
    //退房
    @GetMapping("/updateStatus/{roomcode}/{orderhotel}")
    public Boolean updateStatus(@PathVariable Integer roomcode,
                             @PathVariable String orderhotel){
        return orderService.updateStatus(roomcode,orderhotel);
    }
    //入住
    @GetMapping("/changeStatus/{roomcode}/{orderhotel}")
    public Boolean changeStatus(@PathVariable Integer roomcode,
                                @PathVariable String orderhotel){
        return orderService.changeStatus(roomcode,orderhotel);
    }
    //订单详情
    @GetMapping("/getNow/{id}")
    public OrderVO getNow(@PathVariable Integer id){
        return orderService.getNow(id);
    }
    //接受订单
    @GetMapping("/examNow/{roomcode}/{orderhotel}")
    public Boolean examNow(@PathVariable Integer roomcode,
                           @PathVariable String orderhotel){
        return orderService.examNow(roomcode,orderhotel);
    }
    //拒绝订单
    @GetMapping("/noexamNow/{roomcode}/{orderhotel}")
    public Boolean noexamNow(@PathVariable Integer roomcode,
                             @PathVariable String orderhotel){
        return orderService.noexamNow(roomcode,orderhotel);
    }
    //用户预定酒店
    @PostMapping("/reserveOrder")
    public Boolean reseOrder(@RequestBody OrderVO orders){
        System.out.println(orders.toString());
        Boolean flag = orderService.reseOrders(orders);
        System.out.println(flag);
        return flag;
    }

    @GetMapping("/hotelOrder/{usercode}/{query}/{current}/{size}")
    public Page<OrderVO> getHotelOrder(@PathVariable String usercode,
                                       @PathVariable String query,
                                       @PathVariable Integer current,
                                       @PathVariable Integer size){
        return orderService.getOrderByHotel(usercode,query,current,size);
    }

    @GetMapping("/getOrderData/{usercode}")
    public List<Object> getOrderData(@PathVariable("usercode") String usercode){
        return orderService.getOrderData(usercode);
    }
}
